﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class ContactLiveSupport
    {
         #region Common
        public eContactLiveSupport Data;

        public ContactLiveSupport()
        {
            Data = new eContactLiveSupport();
		}

        ~ContactLiveSupport()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cContactLiveSupport objDAL = new cContactLiveSupport();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cContactLiveSupport objDAL = new cContactLiveSupport();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cContactLiveSupport objInfor = new cContactLiveSupport(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.ContactLiveSupportID;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cContactLiveSupport objInfor = new cContactLiveSupport();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

       

        private void MappingData(cContactLiveSupport objInfor)
        {


            objInfor.Type = Data.Type;


            try { objInfor.AccountName = Data.AccountName; }
            catch { objInfor.AccountName = ""; }

            try { objInfor.Description = Data.Description; }
            catch { objInfor.Description = ""; }

             objInfor.ContactOfficeID = Data.ContactOfficeID; 
            
        }

        private void ConvertData(cContactLiveSupport objInfor)
        {
            Data.Type = objInfor.Type;
            Data.AccountName = objInfor.AccountName;
            Data.Description = objInfor.Description;
            Data.ContactOfficeID = objInfor.ContactOfficeID;
           
        }
        #endregion

        public DataTable Search(int ContactOfficeID)
        {
            DataTable tbResult = new DataTable();
            cContactLiveSupport objDAL = new cContactLiveSupport();
            tbResult = objDAL.Search(ContactOfficeID);
            return tbResult;
        } 
    }
}
